﻿<html>
<head>
<style>
th{
	font-size:12px;
}
td{
	font-size:12px;
}
</style>
</head>
<body>
<?php
@ $matchTime = $_GET["matchTime"];

if ($matchTime == NULL) {
	$matchTime = date('Y-m-d');
}

$config = require 'conf/config.ini.php';      //加载公用config.ini.php
$conn = mysql_connect($config["DB_HOST"], $config["DB_USER"], $config["DB_PWD"]);
mysql_select_db($config["DB_NAME"], $conn);
mysql_query("SET NAMES utf8");

$sql = "select lw.matchTime, lw.matchId, lw.matchOptaId, lw.matchName, lw.homeTeam, lw.visitTeam, lw.count_u, count(r.reviewId) count_r from ";
$sql .= "(";
$sql .= "select m.matchTime,m.matchId, m.matchOptaId, m.matchName, m.homeTeam, m.visitTeam, count(DISTINCT CONCAT( w.matchId, w.userIp, w.userMac )) count_u ";
$sql .= "from live_match m, live_watch w ";
$sql .= "where";
$sql .= "	m.matchId = w.matchId ";
$sql .= "and	left(w.userInTime,10) = '".$matchTime."' ";
$sql .= "group by m.matchId ";
$sql .= ") lw  left join live_review r on lw.matchId = r.matchId ";
$sql .= "group by lw.matchId ";
$sql .= "order by count_u desc";
$matchList = mysql_query($sql, $conn);
?>

<table width="100%" cellspacing="0" cellpadding="2">
	<tr>
	  <th rowspan="2">名次</th>
	  <th rowspan="2">人数</th>
      <th rowspan="2">比赛时间</th>
	  <th rowspan="2">比赛名称</th>
      <th>比赛ID</th>
	  <th>主队名称</th>
	  <th rowspan="2">评论</th>
    </tr>
	<tr>
	    <th>比赛OPTAID</th>
	  	<th>客队名称</th>
  	</tr>
<?php

$color = "";
$i = 0;
while ($match = mysql_fetch_object($matchList)) {

	if ($i++ % 2 == 0) {
		$color = "#B5E7FF";
	} else {
		$color = "#FFFFFF";
	}
	
	echo '<tr align="center" bgcolor="' . $color . '">';
	echo '<td rowspan="2" style="font-size:18; font-weight:bold; font-family:黑体; color:#006699">' . $i . '</td>';
	echo '<td rowspan="2" style="font-size:18; font-weight:bold; font-family:黑体">' . $match->count_u . '</td>';
	echo '<td rowspan="2">' . $match->matchTime . '</td>';
	echo '<td rowspan="2"><a href="get_live_watch_u.php?matchId=' . $match->matchId . '" target="user">' . $match->matchName . '</a></td>';
	echo '<td>' . $match->matchId . '</td>';
	echo '<td>' . $match->homeTeam . '</td>';
	if($match->count_r != "0"){
		echo '<td rowspan="2"><a href="get_live_watch_c.php?matchId=' . $match->matchId . '" target="comment">' . $match->count_r . '</a></td>';
	}else{
		echo '<td rowspan="2">&nbsp;</td>';	
	}
	echo '</tr>';
	echo '<tr align="center" bgcolor="' . $color . '">';
	echo '<td>' . $match->matchOptaId . '</td>';
	echo '<td>' . $match->visitTeam . '</td>';
	echo '</tr>';
}
?>
</table>
</body>
</html>